using System;
using UnityEngine;

public class BossDoor : MonoBehaviour
{
    public enum DoorDirection
    {
        Up,
        Down,
        Left,
        Right
    };
    public float xoffset, yoffset;
    public DoorDirection doorDirection;
    public Transform player;
    public GameObject boss; // 引用BOSS对象
    private BossController bossController;

    private void Start()
    {
        xoffset = 7f;
        yoffset = 12f;
        player = GameObject.FindGameObjectWithTag("Player").transform;
        
    }

    private void Update()
    {
        
        boss=GameObject.FindGameObjectWithTag("Boss");
        bossController = boss.GetComponent<BossController>();
        player = GameObject.FindGameObjectWithTag("Player").transform;
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player") && (boss == null ))
        {
            MoveToNextRoom(doorDirection);
        }
        else
        {
            Debug.Log("Boss is still alive! Defeat the boss to exit the room.");
        }
    }

    public void MoveToNextRoom(DoorDirection direction)
    {
        // 根据玩家当前房间的位置和方向计算下一个房间的位置
        Vector3 currentRoomPosition = player.transform.position;
        // 计算下一个房间的位置   
        Vector3 nextRoomPosition = currentRoomPosition;
        switch (direction)
        {
            case DoorDirection.Up:
                nextRoomPosition += new Vector3(0, yoffset, 0);
                break;
            case DoorDirection.Down:
                nextRoomPosition += new Vector3(0, -yoffset, 0);
                break;
            case DoorDirection.Left:
                nextRoomPosition += new Vector3(-xoffset, 0, 0);
                break;
            case DoorDirection.Right:
                nextRoomPosition += new Vector3(xoffset, 0, 0);
                break;
        }

        // 将玩家移动到下一个房间的位置
        player.transform.position = nextRoomPosition;
    }
}